package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.Feedback_Info;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface User_feedbackMapper {
    @Select("SELECT * FROM project_exam.feedbacks;")
    List<Feedback_Info> selectAll();

    @Select("SELECT * FROM feedbacks WHERE feedback_id = #{feedback_id}")
    Feedback_Info selectByID(int feedback_id);

    @Insert("INSERT INTO feedbacks (user_id, course_id, feedback_type, content, contact, create_time, status, reply_content, reply_time) " +
            "VALUES (#{userId}, #{courseId}, #{feedbackType}, #{content}, #{contact}, now(), #{status}, #{replyContent}, now())")
    int insertFeedback(Feedback_Info feedback);

    @Update("UPDATE feedbacks SET " +
            "user_id = #{userId}, " +
            "course_id = #{courseId}, " +
            "feedback_type = #{feedbackType}, " +
            "content = #{content}, " +
            "contact = #{contact}, " +
            "status = #{status}, " +
            "reply_content = #{replyContent}, " +
            "reply_time = now() " +
            "WHERE feedback_id = #{feedbackId}")
    int updateFeedback(Feedback_Info feedback);

    @Delete("DELETE FROM feedbacks WHERE feedback_id = #{feedback_id}")
    int deleteFeedback(int feedback_id);

    @Select("SELECT * FROM project_exam.feedbacks LIMIT #{offset}, #{pageSize}")
    List<Feedback_Info> selectAllByPage(@Param("offset") int offset, @Param("pageSize") int pageSize);
}